# -*- coding: utf-8 -*-

'''
Created on 18.07.2011

@author: Vlasov A. I. <root@proscript.ru>
'''

from django.db import models

from django.contrib.auth.models import User

DIRECTION_CHOICES = (
    (u'inc', u'Входящая'),
    (u'out', u'Исходящая'),
    (u'rcv', u'Принята'),
    (u'snd', u'Оправлена'),
)

class VyplataBase (models.Model):
    
    name = models.CharField(max_length=100, unique=True)
    title = models.CharField(max_length=100)
    users = models.ManyToManyField(User)

    class Meta:
        ordering = [u'name']
        verbose_name = u'Base'
        
    class Admin:
        list_display = (u'title', u'users')
    
    def __unicode__(self):
        return self.title

class Recipient (models.Model):
    
    name = models.CharField(max_length=100)
    email = models.EmailField()
    
    class Meta:
        ordering = [u'name']
        
    def __unicode__(self):
        return self.name

class ExchangeLog (models.Model):
    
    direction = models.CharField(max_length=3, choices=DIRECTION_CHOICES)
    database = models.ForeignKey('VyplataBase')
    user = models.ForeignKey(User)
    datetime = models.DateTimeField(u'Date')
    filename = models.CharField(max_length=255)

    class Meta:
        ordering = [u'-datetime']
        
    def __unicode__(self):
        return u'Database %s sent/recieved at %s' % (self.database, self.datetime)
    
